package com.zs.members.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gsj.common.pojo.R;
import com.zs.members.dao.ClientMapper;
import com.zs.members.pojo.entity.Client;
import com.zs.members.pojo.vo.ClientVo;
import com.zs.members.service.IClientService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: clms-nine
 * @description: 客户service实现类
 * @author: 张硕
 * @create: 2021-07-23 21:38
 **/
@Service
public class ClientServiceImpl extends ServiceImpl<ClientMapper,Client> implements IClientService {
    @Autowired
    private ClientMapper clientMapper;

    @Override
    public R get(Integer currentPage, Integer pageSize, ClientVo clientVo) {
        Page<Client> clientPage = new Page<>(currentPage,pageSize);
        QueryWrapper<Client> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(clientVo.getAddress())){
            wrapper.like("address",clientVo.getAddress());
        }
        if (StringUtils.isNotEmpty(clientVo.getContactAddress())){
            wrapper.like("contact_address",clientVo.getContactAddress());
        }
        if (StringUtils.isNotEmpty(clientVo.getContactName())){
            wrapper.like("contact_name",clientVo.getContactName());
        }
        if (StringUtils.isNotEmpty(clientVo.getUsername())){
            wrapper.like("username",clientVo.getUsername());
        }
        if (StringUtils.isNotEmpty(clientVo.getName())){
            wrapper.like("name",clientVo.getName());
        }
        if (clientVo.getId()!=null){
            wrapper.like("id",clientVo.getId());
        }
        Page<Client> page = clientMapper.selectPage(clientPage, wrapper);
        return R.ok().put("records",page.getRecords()).put("total",page.getTotal());
    }
}
